package com.chief.test.controller;

import com.alibaba.csp.sentinel.annotation.SentinelResource;
import com.alibaba.csp.sentinel.slots.block.BlockException;
import com.chief.SentinelService;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Random;


@RestController
public class IndexController {


    @DubboReference
    private SentinelService sentinelService;

    @SentinelResource(value = "index",blockHandler = "ss")
    @RequestMapping("/index")
    public String index() {
        Random random = new Random();
        int i = random.nextInt(5);
        if(i<3){
            System.out.println(i/0);
        }
        return sentinelService.test();
    }

    public String ss(BlockException blockException) {
        blockException.printStackTrace();
        return "indexblockException";
    }

}
